package com.ww.springboot.mybatis.data.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ww.springboot.mybatis.data.entity.OnlineChannelServiceBindStoreEntity;
import com.ww.springboot.mybatis.data.service.IOnlineChannelServiceBindStoreService;
import com.ww.springboot.mybatis.mapper.OnlineChannelServiceBindStoreMapper;
import com.ww.springboot.mybatis.util.ExceptionUtil;
import com.ww.springboot.mybatis.util.Func;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 服务实现类
 *
 * @author Chill
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class OnlineChannelServiceBindStoreServiceImpl extends ServiceImpl<OnlineChannelServiceBindStoreMapper, OnlineChannelServiceBindStoreEntity> implements IOnlineChannelServiceBindStoreService {

    /**
     * 根据线上绑定服务id删除店铺信息
     *
     * @param ocsbIds "线上绑定服务id，多个用“,”分割
     * @return true 成功  false 失败
     */
    @Override
    public void deleteByOcsbIds(String ocsbIds) {
        List<Long> ocsbIdList = Func.toLongList(ocsbIds);
        ExceptionUtil.checkArgument(CollUtil.isEmpty(ocsbIdList), "线上绑定服务id不能为空");
        baseMapper.deleteBatchByOcsbIds(ocsbIdList);
    }

    /**
     * 自定义批量插入
     *
     * @param list 批量插入
     * @return true 成功  false 失败
     */
    @Override
    public boolean insertBatch(List<OnlineChannelServiceBindStoreEntity> list) {
        return baseMapper.insertBatch(list) > 0;
    }

    @Override
    public boolean insert(OnlineChannelServiceBindStoreEntity entity) {
        return baseMapper.insert(entity) > 0;
    }


    @Override
    public List<OnlineChannelServiceBindStoreEntity> getByStoreCode(List<Long> ocsbIds, String storeCode) {
        return lambdaQuery().in(OnlineChannelServiceBindStoreEntity::getOcsbId, ocsbIds)
                .eq(OnlineChannelServiceBindStoreEntity::getStoreCode, storeCode).list();
    }
}
